package bishi.day16_5_12;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author 是阿秋啊
 * @date 2022/05/12 20:51
 **/
public class poker_max {
    static Map<String, Integer> map = new HashMap<String, Integer>() {
        {
            put("3", 1);
            put("4", 2);
            put("5", 3);
            put("6", 4);
            put("7", 5);
            put("8", 6);
            put("9", 7);
            put("10", 8);
            put("J", 9);
            put("Q", 10);
            put("K", 11);
            put("A", 12);
            put("2", 13);
        }
    };

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String s = sc.nextLine();
            String[] str = s.split("-");
            String[] ch1 = str[0].trim().split(" ");
            String[] ch2 = str[1].trim().split(" ");
            if (isTwoJoker(ch1) || isTwoJoker(ch2)) {
                System.out.println("joker JOKER");
                continue;
            }
            if (ch1.length == 4 ^ ch2.length == 4) {
                String[] tmp;
                if (ch1.length == 4) {
                    tmp = ch1;
                } else {
                    tmp = ch2;
                }
                for (int i = 0; i < tmp.length; i++) {
                    if (i == 3) {
                        System.out.println(tmp[i]);
                        break;
                    }
                    System.out.print(tmp[i] + " ");
                }
                continue;
            }
            if (ch1.length != ch2.length) {
                System.out.println("ERROR");
                continue;
            }
            helper(ch1, ch2);
        }
    }

    private static boolean isTwoJoker(String[] s) {
        if (s.length != 2) {
            return false;
        }
        return s[0].charAt(0) == 'j';
    }

    private static void helper(String[] ch1, String[] ch2) {
        int len = ch1.length;
        // 大于二是因为有10的存在
        if (ch1[0].length() > 2 && ch2[0].length() > 2) {
            System.out.println(ch1[0].charAt(0) == 'J' ? ch1[0].toString() : ch2[0].toString());
            return;
        }
        if (ch1[0].length() > 2) {
            System.out.println(ch1[0].toString());
            return;
        }
        if (ch2[0].length() > 2) {
            System.out.println(ch2[0].toString());
            return;
        }
        print(map.get(ch1[0]) > map.get(ch2[0]) ? ch1 : ch2);
    }

    private static void print(String[] s) {
        int len = s.length;
        for (int i = 0; i < len; i++) {
            if (i == len - 1) {
                System.out.println(s[i]);
                break;
            }
            System.out.print(s[i] + " ");
        }
    }

}